#ifndef ONE_WIRE_H
#define ONE_WIRE_H
	
	/* DS18s20 transaction sequence:(everytime)
	step1: initialization
		master:send reset_pulse
		slave:send presence_pulse{
			master.mode=output
			send 0 for minimum 480us
			master.mode=input
			after 15us-60us slave transmits low for 60us-240us 
			
		}
		
	step2: ROM Command
		read rom[33h]
	
	step3: DS18S20 Function Command
		convert T[44h]
		Read scratchpad[BEh]
		(send reset_pulse to finish after 
		reading byte0 and byte1)
		
		*/
		
#define THERM_DDR DDRB
#define THERM_DQ 0
#define THERM_PORT PORTB
#define THERM_PIN PINB

#define THERM_INPUT_MODE() THERM_DDR&=~(1<<THERM_DQ)
#define THERM_OUTPUT_MODE() THERM_DDR|=(1<<THERM_DQ)
#define THERM_LOW() THERM_PORT&=~(1<<THERM_DQ)
#define THERM_HIGH() THERM_PORT|=(1<<THERM_DQ)

#define THERM_CMD_CONVERTTEMP 0x44
#define THERM_CMD_RSCRATCHPAD 0xbe
#define THERM_CMD_WSCRATCHPAD 0x4e
#define THERM_CMD_CPYSCRATCHPAD 0x48
#define THERM_CMD_RECEEPROM 0xb8
#define THERM_CMD_RPWRSUPPLY 0xb4
#define THERM_CMD_SEARCHROM 0xf0
#define THERM_CMD_READROM 0x33
#define THERM_CMD_MATCHROM 0x55
#define THERM_CMD_SKIPROM 0xcc
#define THERM_CMD_ALARMSEARCH 0xec
unsigned char temperature[2];

void read_temperature(void);

#endif